package com.user.domain.factory;

import cn.hutool.core.bean.BeanUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.security.domain.authority.CommonUserDetails;
import com.user.application.command.cmd.UserCommand;
import com.user.application.query.dto.UserDto;
import com.user.domain.entity.User;
import com.user.infrastructure.entity.UserDao;
import lombok.SneakyThrows;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;

/**
 * @author 大忽悠
 * @create 2022/9/15 22:00
 */
public class UserFactory {
    public static UserConverter USER_CONVERT = Mappers.getMapper(UserConverter.class);
    public static UserDaoConverter USER_DAO_CONVERT = Mappers.getMapper(UserDaoConverter.class);

    /**
     * 转换器
     */
    @Mapper
    public interface UserConverter {
        @Mappings({
                @Mapping(target = "ipAddr",ignore = true),
                @Mapping(target = "headImg",ignore = true)
        })
         User toUser(UserCommand userCommand);
         User toUser(UserDao userDao);

         UserCommand toUserCommand(User user);
         UserDao toUserDao(User user);
    }

    @Mapper
    public interface UserDaoConverter {
        @Mappings({
                @Mapping(target = "signInNum",ignore = true),
        })
        List<UserDto> toUserDtoList(List<UserDao> userDaos);
    }


}
